$(function(){
//	获取租户列表
	$.ajax({
			type:"get",
			url:serverIP+"/user/util/GetCustomList",
			dataType:"json",
			async:false,
			xhrFields: {
                withCredentials: true    // 设置sessionId相同
            },
			success:function (data) {
				$.each(data.data, function(index,obj) {
					$('#sl-customer select').append('<option value='+obj.customerId+'>'+obj.name+'</option>');
				})
			}
	})
//	租户打印纸张查询
	$("#sl-customer select").change(function(){
		echarsGet();
		$('#month').click();
	})
	myChartContainer();
	echarsGet();
	$('#month').click();
})
//每月租户打印纸量图表统计
var myChartContainer = function () {
	$(".error-tbody").width( $(".error-div").width()+'px');
	$(".error-tbody").height( $(".admin").height()*1/2-105+'px');
	$(".main-div").height( $(".admin").height()*1/2+20+'px');
	$(".outMaintainer").height( $(".admin").height()*1/2-100+'px');
	$(".outMaintainer-tbody").width( $(".main-div").width()+'px');
	$(".outMaintainer-tbody").height( $(".admin").height()*1/2-167+'px');
	var obj=$(".error-tbody"); 
	if(obj.prop('scrollHeight')>obj.prop('clientHeight')||obj.prop('offsetHeight')>obj.prop('clientHeight')){
	$('.error-tbody').width( $(".error-div").width()+16+'px');
	}
	var obj1=$(".outMaintainer-tbody"); 
	if(obj1.prop('scrollHeight')>obj1.prop('clientHeight')||obj1.prop('offsetHeight')>obj1.prop('clientHeight')){
	$('.outMaintainer-tbody').width( $(".main-div").width()+16+'px');
	}
};
function echarsGet(){
	$('#chart-month').height($("#echarts-div").height()-32+'px');
	$('#chart-week').height($("#echarts-div").height()-32+'px');
	$('#chart-day').height($("#echarts-div").height()-32+'px');
	customId=$("#sl-customer select").val();
}
$('#month').click(function(){
	$('#echarts-div>div').css('display','none');
	$('#echarts-div>span').css('background','#ccc');
	$('#chart-month').css('display','block');
	$('#month').css('background','#00A4AC');
	myChartMonth = echarts.init(document.getElementById('chart-month'));
	myChartMonth.resize();
	$.ajax({
			type:"post",
			url:serverIP+"/user/index/MonthList",
			dataType:"json",
			xhrFields: {
                withCredentials: true    // 设置sessionId相同
            },
			data:{
				"customId":customId
			},
			success:function (data) {
			  	var list =   new Array();
			  	var list2 =   new Array(); 
			  	var list3 =   new Array();
  		 
			  	for(var i in data.data){
				  		var date=data.data[i].mouth;
				  		date =date.slice(5);
					    list.push(data.data[i].mouth);
					    list2.push(data.data[i].monoNum);
					    list3.push(data.data[i].colorNum);
				}
			  	myChartMonth.setOption({
				    toolbox: {
				        feature: {
				            restore: {},
				            saveAsImage: {}
				        }
				    },
				    tooltip : {
				        trigger: 'axis',
				        axisPointer: {
				            type: 'cross',
				            animation: false,
				            label: {
				                backgroundColor: '#505765'
				            }
				        }
				    },
				    legend: {
				        data:['黑白纸张','彩色纸张']
				    },
				    xAxis: [
				        {
				            type: 'category',
				            data: list,
				            axisPointer: {
				                type: 'shadow'
				            }
				        }
				    ],
				    yAxis: [
				        {
				            type: 'value',
				            name: '月打印纸张量 (张)',
				        }
				    ],
				    series: [
				        {
				            name:'黑白纸张',
				            type:'bar',
				            itemStyle:{
			                    normal:{
			                        color:'#2F4554'
			                    }
			                },
				            data:list2
				        },
				        {
				            name:'彩色纸张',
				            type:'bar',
				            itemStyle:{
			                    normal:{
			                        color:'#C23531'
			                    }
			                },
				            data:list3
				        } 
				    ]
				});
			}
	});
})
$('#week').click(function(){
	$('#echarts-div>div').css('display','none');
	$('#echarts-div>span').css('background','#ccc');
	$('#chart-week').css('display','block');
	$('#week').css('background','#00A4AC');
	myChartWeek = echarts.init(document.getElementById('chart-week'));
	myChartWeek.resize();
	$.ajax({
			type:"post",
			url:serverIP+"/user/index/WeekList",
			dataType:"json",
			xhrFields: {
                withCredentials: true    // 设置sessionId相同
            },
			data:{
				"customId":customId
			},
			success:function (data) {
			  	var list =   new Array();
			  	var list2 =   new Array(); 
			  	var list3 =   new Array();
  		 
			  	for(var i in data.data){
				  		var date=data.data[i].week;
				  		date =date.slice(4);
					    list.push(date+'周');
					    list2.push(data.data[i].monoNum);
					    list3.push(data.data[i].colorNum);
				}
			  	myChartWeek.setOption({
				    toolbox: {
				        feature: {
				            restore: {},
				            saveAsImage: {}
				        }
				    },
				    tooltip : {
				        trigger: 'axis',
				        axisPointer: {
				            type: 'cross',
				            animation: false,
				            label: {
				                backgroundColor: '#505765'
				            }
				        }
				    },
				    legend: {
				        data:['黑白纸张','彩色纸张']
				    },
				    xAxis: [
				        {
				            type: 'category',
				            data: list,
				            axisPointer: {
				                type: 'shadow'
				            }
				        }
				    ],
				    yAxis: [
				        {
				            type: 'value',
				            name: '周打印纸张量 (张)',
				        }
				    ],
				    series: [
				        {
				            name:'黑白纸张',
				            type:'bar',
				            itemStyle:{
			                    normal:{
			                        color:'#2F4554'
			                    }
			                },
				            data:list2
				        },
				        {
				            name:'彩色纸张',
				            type:'bar',
				            itemStyle:{
			                    normal:{
			                        color:'#C23531'
			                    }
			                },
				            data:list3
				        } 
				    ]
				});
			}
	});
})
$('#day').click(function(){
	$('#echarts-div>div').css('display','none');
	$('#echarts-div>span').css('background','#ccc');
	$('#chart-day').css('display','block');
	$('#day').css('background','#00A4AC');
	myChartDay = echarts.init(document.getElementById('chart-day'));
	myChartDay.resize();
	$.ajax({
			type:"post",
			url:serverIP+"/user/index/DayList",
			dataType:"json",
			xhrFields: {
                withCredentials: true    // 设置sessionId相同
            },
			data:{
				"customId":customId
			},
			success:function (data) {
			  	var list =   new Array();
			  	var list2 =   new Array(); 
			  	var list3 =   new Array();
  		 
			  	for(var i in data.data){
				  		var date=data.data[i].day;
				  		date =date.slice(5);
					    list.push(date);
					    list2.push(data.data[i].monoNum);
					    list3.push(data.data[i].colorNum);
				}
			  	myChartDay.setOption({
				    toolbox: {
				        feature: {
				            restore: {},
				            saveAsImage: {}
				        }
				    },
				    tooltip : {
				        trigger: 'axis',
				        axisPointer: {
				            type: 'cross',
				            animation: false,
				            label: {
				                backgroundColor: '#505765'
				            }
				        }
				    },
				    legend: {
				        data:['黑白纸张','彩色纸张']
				    },
				    xAxis: [
				        {
				            type: 'category',
				            data: list,
				            axisPointer: {
				                type: 'shadow'
				            }
				        }
				    ],
				    yAxis: [
				        {
				            type: 'value',
				            name: '日打印纸张量 (张)',
				        }
				    ],
				    series: [
				        {
				            name:'黑白纸张',
				            type:'bar',
				            itemStyle:{
			                    normal:{
			                        color:'#2F4554'
			                    }
			                },
				            data:list2
				        },
				        {
				            name:'彩色纸张',
				            type:'bar',
				            itemStyle:{
			                    normal:{
			                        color:'#C23531'
			                    }
			                },
				            data:list3
				        } 
				    ]
				});
			}
	});
})
$(function(){
//	报错列表
	$.ajax({
			type:"post",
			url:serverIP+"/user/index/FaultList",
			dataType:"json",
			xhrFields: {
                withCredentials: true    // 设置sessionId相同
            },
			data:{
				"dealerId":12
			},
			success:function (data) {
				let result=data.data;
				var strVar = "";
				result.map(function(u){
					strVar += "              <tr>";
				    strVar += "                <td>"+u.cName+"<\/td>\n";
				    strVar += "                <td>"+u.pName+"<\/td>\n";
				    strVar += "                <td>"+u.codeName+"<\/td>\n"; 
				    strVar += "                <td>\n";
				    strVar += "                  <button class=\"btn\" value="+u.taskId+">\n";
				    strVar += "                    详情  <span class=\"error-num\">"+u.faultNum+"</span>\n";
				    strVar += "                  </button>\n";
				    strVar += "                <\/td>\n";
				    strVar += "              <\/tr>";
				})
				$('.error-tbody').append(strVar);
			}
	})
//	外出维护人员
	$.ajax({
			type:"post",
			url:serverIP+"/user/index/MaintList",
			dataType:"json",
			xhrFields: {
                withCredentials: true    // 设置sessionId相同
            },
			data:{
				"dealerId":12
			},
			success:function (data) {
				let result=data.data;
				var strVar = "";
				result.map(function(u){
					strVar += "              <tr>";
				    strVar += "                <td class=\"pid\">"+u.mName+"<\/td>\n";
				    strVar += "                <td>"+u.phone+"<\/td>\n";
				    strVar += "                <td>"+"<font color='red'>维修中</font>"+"<\/td>\n";
				    strVar += "                <td>"+u.pName+"<\/td>\n";
				    strVar += "                <td>"+u.cName+"<\/td>\n";
				    strVar += "                <td>"+u.remark+"<\/td>\n";
				    strVar += "                <td>"+u.taskExplain	+"<\/td>\n"; 
				    strVar += "              <\/tr>";
				})
				$('.outMaintainer-tbody').append(strVar);
			}
	})
})/*$function-End*/
$("body").on("click",".btn",function(){
	var taskId=$(this).val();
	window.location.href="task.html?id="+taskId;
})
//监听浏览器窗口变化
window.onresize = function(){
	var bodyH=$("body").height();
	$(".leftbar").height(bodyH-45+"px");
	$(".content").height(bodyH-45+"px");
	$(".admin").height($(".content").height()-45+"px");
	myChartContainer();
	echarsGet();
    myChartMonth.resize();
    myChartWeek.resize();
    myChartDay.resize();
}
//商城
$('.set-info').hover(function(){
	$('.mall').toggle();
})
